#nohup python run.py >log.txt 2>&1 &
from wsgiref.simple_server import make_server
from flask import Flask, render_template, request

import getKey
import putValue

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('./page/index.html')


@app.route('/get')
def get():
    #print(request.args)
    #t = {"a":1,"b":2}
    # get请求，打印url后面所有的参数（key:value形式），如果有多个参数，通过request.args.get('key')的方式获取值
    #return json.dumps(t,ensure_ascii=False)
    return getKey.getKey(request.args["key"])


@app.route('/put', methods=['POST'])
def put():
    # post请求。获取模版语言中输入框输入的值
    # t = {"a":1,"b":2}
    # get请求，打印url后面所有的参数（key:value形式），如果有多个参数，通过request.args.get('key')的方式获取值
    # return json.dumps(t,ensure_ascii=False)
    #data = request.get_json()                # 获取 JSON 数据
    data = request.data.decode("utf-8", 'strict').strip('[]').split(",")
    data = list(map(int,data))
    return putValue.put(request.args["key"], data)


if __name__ == '__main__':
    server = make_server('127.0.0.1', 5000, app)
    server.serve_forever()
    app.run(threaded=True)
